package com.chengfei.rabbitmq;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author chengfei cheng.fei@chinaott.onaliyun.com
 **/
@Configuration
public class RabbitMQConfiguration {
    public static final String QUEUE_NAME = "spring-boot-simple";
    public static final String TOPIC_QUEUE_NAME1 = "topic1-simple";
    public static final String TOPIC_QUEUE_NAME2 = "topic2-simple";
    public static final String TOPIC_EXCHANGE = "topic-exchange";
    public static final String FANOUT_EXCHANGE = "fanout_exchange";

    public static final String TOPIC_ROUTING_KEY1 = "topic.key1";
    public static final String TOPIC_ROUTING_KEY2 = "topic.#";

    /**
     * 配置队列
     * @return
     */
    @Bean
    public Queue queue(){
        return new Queue(QUEUE_NAME,true);
    }
    @Bean
    public Queue topicQueue1(){
        return new Queue(TOPIC_QUEUE_NAME1,true);
    }
    @Bean
    public Queue topicQueue2(){
        return new Queue(TOPIC_QUEUE_NAME2,true);
    }

    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(TOPIC_EXCHANGE);
    }

    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange(FANOUT_EXCHANGE);
    }
    @Bean
    public Binding topicBinding1(){
        return BindingBuilder.bind(topicQueue1()).to(topicExchange()).with(TOPIC_ROUTING_KEY1);
    }
    @Bean
    public Binding topicBinding2(){
        return BindingBuilder.bind(topicQueue2()).to(topicExchange()).with(TOPIC_ROUTING_KEY2);
    }

    @Bean
    public Binding fanoutBinding1(){
        return BindingBuilder.bind(topicQueue1()).to(fanoutExchange());
    }

    @Bean
    public Binding fanoutBinding2(){
        return BindingBuilder.bind(topicQueue2()).to(fanoutExchange());
    }
}
